<template>
  <div class="teaching-plan-form">
    <div class="form-header">
      <el-button class="back-button" @click="$emit('close')" circle size="small">
        ←
      </el-button>
      <h2>教学教案生成</h2>
    </div>

    <div class="form-content">
      <!-- 年龄选择 -->
      <div class="form-section">
        <label class="form-label">年龄:</label>
        <div class="option-group">
          <el-button v-for="age in ageOptions" :key="age" :type="selectedAge === age ? 'primary' : 'default'"
            @click="selectedAge = age" class="option-button">
            {{ age }}
          </el-button>
        </div>
      </div>

      <!-- 活动类型选择 -->
      <div class="form-section">
        <label class="form-label">活动类型:</label>
        <div class="option-group">
          <el-button v-for="type in activityTypes" :key="type"
            :type="selectedActivityType === type ? 'primary' : 'default'" @click="selectedActivityType = type"
            class="option-button">
            {{ type }}
          </el-button>
        </div>
      </div>

      <!-- 活动名称输入 -->
      <div class="form-section">
        <label class="form-label">活动名称:</label>
        <el-input v-model="activityName" type="textarea" :rows="4" placeholder="请输入活动名称" class="activity-name-input" />
      </div>

      <!-- 一键生成按钮 -->
      <el-button type="primary" @click="generatePlan" :disabled="!canGenerate" class="generate-button" size="large">
        一键生成
      </el-button>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'

const emit = defineEmits(['close', 'generate'])

const ageOptions = ['托班', '小班', '中班', '大班']
const activityTypes = ['健康领域', '语言领域', '社会领域', '体育活动', '音乐活动', '安全活动']

const selectedAge = ref('')
const selectedActivityType = ref('')
const activityName = ref('')

const canGenerate = computed(() => {
  return selectedAge.value && selectedActivityType.value && activityName.value.trim()
})

const generatePlan = () => {
  if (!canGenerate.value) {
    return
  }

  // 拼接提示词
  const prompt = `请为我生成一篇教学教案要求如下：
年龄：${selectedAge.value}
活动类型：${selectedActivityType.value}
活动名称：${activityName.value}`

  // 发送生成事件，传递提示词
  emit('generate', prompt)

  // 关闭表单页面
  emit('close')
}
</script>

<style scoped>
.teaching-plan-form {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: rgba(255, 255, 255, 0.98);
  overflow-y: auto;
}

.form-header {
  display: flex;
  align-items: center;
  padding: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 10;
}

.back-button {
  margin-right: 10px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  font-size: 18px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-button:hover {
  background: rgba(255, 255, 255, 0.3);
}

.form-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.form-content {
  flex: 1;
  padding: 20px 15px;
  overflow-y: auto;
}

.form-section {
  margin-bottom: 25px;
}

.form-label {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 12px;
}

.option-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.option-button {
  flex: 1;
  min-width: 80px;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  transition: all 0.3s ease;
}

.option-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.activity-name-input {
  width: 100%;
}

.activity-name-input :deep(.el-textarea__inner) {
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  border: 2px solid #e0e0e0;
  transition: all 0.3s ease;
}

.activity-name-input :deep(.el-textarea__inner):focus {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.generate-button {
  width: 100%;
  margin-top: 30px;
  padding: 15px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 25px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  transition: all 0.3s ease;
}

.generate-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.generate-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 移动端优化 */
@media (max-width: 480px) {
  .form-content {
    padding: 15px 12px;
  }

  .form-label {
    font-size: 15px;
  }

  .option-button {
    font-size: 13px;
    padding: 8px 12px;
    min-width: 70px;
  }

  .generate-button {
    padding: 12px;
    font-size: 15px;
  }
}
</style>
